package com.rc.saas.tenant.service.discount;

import com.rc.saas.tenant.common.vo.TResponse;
import com.rc.saas.tenant.mapper.discount.TenantDiscountStationMapper;
import com.rc.saas.tenant.model.discount.TenantDiscountStation;
import com.rc.saas.tenant.vo.discount.DiscountStationSaveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author frog
 * @date 2019/11/25
 */
@Service
public class TenantDiscountStationServiceImpl implements TenantDiscountStationService {
    @Autowired
    private TenantDiscountStationMapper tenantDiscountStationMapper;

    @Override
    public TenantDiscountStationMapper getMapper() {
        return tenantDiscountStationMapper;
    }

    @Override
    public TResponse saveEnterpriseStation(String tenant, List<DiscountStationSaveVo> discountStationSaveVOS) {
        if (!CollectionUtils.isEmpty(discountStationSaveVOS)) {
            for (DiscountStationSaveVo discountStationSaveVo : discountStationSaveVOS) {
                TenantDiscountStation tenantDiscountStation = new TenantDiscountStation();
                tenantDiscountStation.setTenantCode(tenant);
                tenantDiscountStation.setDiscountPolicyId(discountStationSaveVo.getDiscountPolicyId());
                tenantDiscountStation.setElecStationId(discountStationSaveVo.getEnterpriseStationList());
                tenantDiscountStationMapper.insertSelective(tenantDiscountStation);
            }
        }

        return TResponse.SUCCESS();
    }
}
